package eerbaar.v2.client.ui;

import eerbaar.game.IGame;
import eerbaar.level.ILevel;
import eerbaar.message.lib.LevelChangeMsg;
import eerbaar.shared.message.IMessageReader;
import eerbaar.shared.message.Message;
import eerbaar.shared.message.MsgHelper;
import eerbaar.v2.app.GameHelper;
import eerbaar.v2.app.core.IGamePanelListener;

public class LevelPanel extends GameStatusPanel {

    public LevelPanel(IGamePanelListener listener) {
        super(listener, "Level:", 1);
        init();
    }

    private void init() {

        IMessageReader reader = new IMessageReader() {

            @Override
            public boolean read(Message msg) {

                IGame game = GameHelper.getGame();
                if (game == null) {
                    return false;
                }

                ILevel level = game.getLevel();
                LevelPanel.this.setValue(level.getIndex());
                String goal = level.getGoal();
                LevelPanel.this.setExtra(goal);

                return false;
            }
        };
        MsgHelper.registerReader(LevelChangeMsg.class, reader);
    }

}
